{include file="../application/admin/view/header.html" /}
</head>
<body>
<div class="container">
	<div class="col-md-12">
		<div class="alert kesn_prompt"></div>
	</div>

	<form class="row form-inline">
	  <div class="form-group">
	     <label for="user_name">用户名:</label>
	    <input type="text" class="form-control" id="user_name" placeholder="">
	  </div>&nbsp;&nbsp;
	  <div class="form-group">
	    <label for="password">密码:</label>
	    <input type="password" class="form-control" id="password" placeholder="">
	  </div>
	</form>
	
	
	&nbsp;&nbsp;<br/>
	<div></div>
	<div class="row">
		<table class="table table-hover">
			<thead>
				<th>#</th>
				<th>模块</th>
				<th>赋权</th>
			</thead>
			<tbody>
			{volist name="modules" id="module"}
			<tr class="_item">
				<th scrope="row">{$module.id}</th>
				<td>{$module.module}</td>
				<td>
				<div>
					<!-- <a href="#" class="btn btn-primary">编辑<span class="fui-new btn-tip"></span></a> -->
					<span class="mrl">
            			<div class="bootstrap-switch bootstrap-switch-wrapper bootstrap-switch-animate bootstrap-switch-id-custom-switch-07 bootstrap-switch-off" data-_module_id="{$module.id}"><div class="bootstrap-switch-container"><span class="bootstrap-switch-handle-on bootstrap-switch-success">ON</span><label class="bootstrap-switch-label">&nbsp;</label><span class="bootstrap-switch-handle-off bootstrap-switch-default">OFF</span><input type="checkbox" checked="" data-toggle="switch" name="switch-07" data-on-color="success" id="custom-switch-07"></div>
            			</div>
          			</span>
					</div>
				</td>
			</tr>
			{/volist}
		</tbody>
		</table>
	</div>
	{$page}
	<button class="btn btn-info admin_save">保存</button>
</div>

{include file="../application/admin/view/footer.html" /}
<script type="text/javascript">
$('.mrl').on('click','.bootstrap-switch',function(){
	var _this = $(this);
	if (_this.hasClass('bootstrap-switch-on')){
		_this.removeClass('bootstrap-switch-on');
		_this.addClass('bootstrap-switch-off');
	}else if (_this.hasClass('bootstrap-switch-off')) {
		_this.removeClass('bootstrap-switch-off');
		_this.addClass('bootstrap-switch-on');
	}
});
//保存修改
$('.container').on('click','.admin_save',function(){
	var _this = $(this);
	var dataArr = {};
	var user_name_tmp = $("#user_name").val();
	var password_tmp = $("#password").val();
	user_name_tmp = $.trim(user_name_tmp);
	password_tmp = $.trim(password_tmp);
	if (user_name_tmp == '' || password_tmp == '') {
		kesn_prompt('fail','用户名和密码不能为空');
		return;
	}
	dataArr['user_name'] = user_name_tmp;
	dataArr['password'] = password_tmp;
	dataArr['modules_power'] = new Array();
	$('._item').each(function(i){
		var this_i = $(this);
		var this_power = this_i.find(".mrl").children('.bootstrap-switch');
		if (this_power.hasClass('bootstrap-switch-on')) {
			var modules_power_tmp = this_power.attr('data-_module_id');
			dataArr['modules_power'].push(modules_power_tmp);
		}
	});
	$.ajax({
			url :'save',
			async:true,
			type:'POST',
			data:dataArr,
			dataType:'JSON',
			success:function(data,textStatus,jqXHR){
    				if (data.err != '0') {
    					kesn_prompt('fail',data.content);
    				}else if (data.err == '0') {
                        kesn_prompt('success',data.content);
                        _this.attr('disabled','disabled');
                    }

    			},
    			error:function(){
    				kesn_prompt('fail','网络出错');
    			}
		});
});

</script>
</footer>
</body>
</html>